package com.felix.test;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import org.apache.http.client.methods.HttpPost;
import org.apache.http.message.BasicNameValuePair;

import com.felix.util.EnhancedHttpUtil;


public class ChatTestB {
	public static String sendURL="http://x.huango.cn:8083/shun/Auto?funid=11&tid=0&cid=409&send=18&rec=14";
	public static String GETURL="http://x.huango.cn:8083/shun/Auto?funid=11&tid=1&cid=409&send=14&rec=18&pmkey="; 
	public static int mpkey=0;
	public static class MyThread extends Thread {
		@Override
		public void run() {
			
			String res=null;
			while (true) {
				try {
					sleep(1000);
					res = EnhancedHttpUtil.getString(GETURL+mpkey, 10);					
					mpkey=ChatXml.showMsg(res);
					


				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		
	}
	public static void sendMessage(String msg){
//		String url=sendURL+msg;
		String res = null;
		List<BasicNameValuePair> params=new ArrayList<BasicNameValuePair>();
		params.add(new BasicNameValuePair("msg", msg));   
		params.add(new BasicNameValuePair("name", "我叫14"));  
		try {
			HttpPost post = EnhancedHttpUtil.getPost(sendURL, params);
			res=EnhancedHttpUtil.getString(post, 10);
			mpkey=ChatXml.afterSend(res);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		System.out.println("B启动一个线程，读取消息...");
		new MyThread().start();
		while(true){
			System.out.print("请输入：");
			Scanner scanner=new Scanner(System.in);
			String mms=scanner.next();
			sendMessage(mms);
			System.out.println("发送完毕。");
		}
		
	}
	
	


}


